package com.miao.api;

import com.miao.base.exception.XueChengPlusException;
import com.miao.base.model.PageResult;
import com.miao.dto.MyCourseTableParams;
import com.miao.dto.XcChooseCourseDto;
import com.miao.dto.XcCourseTablesDto;
import com.miao.po.XcCourseTables;
import com.miao.service.XcChooseCourseService;
import com.miao.service.XcCourseTablesService;
import com.miao.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr.M
 * @version 1.0
 * @description 我的课程表接口
 * @date 2022/10/25 9:40
 */


@Slf4j
@RestController
public class MyCourseTablesController {

    @Autowired
    private XcChooseCourseService  chooseCourseService;
    @Autowired
    private XcCourseTablesService courseTablesService;

    //添加课程(收费|付费)
    @PostMapping("/choosecourse/{courseId}")
    public XcChooseCourseDto addChooseCourse(@PathVariable("courseId") Long courseId) {
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String userId = user.getId();
        return chooseCourseService.addChooseCourse(userId, courseId);
    }

    //查看学习状态
    @PostMapping("/choosecourse/learnstatus/{courseId}")
    public XcCourseTablesDto getLearnstatus(@PathVariable("courseId") Long courseId) {
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String userId = user.getId();
        return chooseCourseService.getLearnStatusDto(userId, courseId);
    }

    //获取我的课程表
    @GetMapping("/mycoursetable")
    public PageResult<XcCourseTables> mycoursetable(MyCourseTableParams params) {
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String userId = user.getId();
        params.setUserId(userId);
        return courseTablesService.myCourseTable(params);
    }
}
